package com.david.elasticjob.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.david.elasticjob.service.PersonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author David
 * @version V1.0
 * @Package com.david.elasticjob
 * @date 2021/5/4 16:52
 */
@Component
public class PersonJob implements SimpleJob {

    private static final Logger LOGGER= LoggerFactory.getLogger(PersonJob.class);
    @Autowired
    private PersonService personService;
    @Value("${server.port}")
    private Integer port;
    @Override
    public void execute(ShardingContext context) {
        String taskId = context.getTaskId();
        String shardingParameter = context.getShardingParameter();
        LOGGER.info("端口：{},定时任务开始：taskId:{},shardingParameter:{}",port,taskId,shardingParameter);
        personService.doSomething(Integer.valueOf(shardingParameter));
    }
}
